<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/7/10 0010
 * Time: 17:12
 */
namespace App\Ordersys\Models;

use App\Admin\Models\MemberModel;
use App\Base\Models\BaseModel;

class OrdersysOrderLogModel extends  BaseModel {
    /**
     * 表名
     * @var string
     */
    public $table="ordersys_order_log";
    /**
     * 时间自动
     * @var bool
     */
    public $timestamps=true;
    /**
     * The name of the "created at" column.
     *
     * @var string
     */
    const CREATED_AT = 'create_time';  //修改添加时间字段
    /**
     * The name of the "updated at" column.
     *
     * @var string
     */
    const UPDATED_AT = 'update_time';

    /**
     * 删除
     */
    const DELETED_AT = 'delete_time';
    /**
     * 模型的日期字段保存格式。
     */
    protected $dateFormat = 'U';

    /**
     * @return MemberModel
     */
    public function getMemberModel(){
        return   app()->make(MemberModel::class);
    }


    /**
     * @param $orderInfo
     * @param $orderType 10审核通过20退款
     * @return bool
     */
    public function saveData($orderInfo,$orderType){
        $data=array();
        $data["day_time"]=strtotime(date("Y-m-d",$orderInfo->add_time));
        $data["order_id"]=$orderInfo->id;
        if($orderType==20){
            $data["all_amount"]=-$orderInfo->refund_amount;
        }else{
            $data["all_amount"]=$orderInfo->all_amount;
        }
        $data['paid_amount']=$orderInfo->paid_amount;
        $data["order_type"]=$orderInfo->order_type;
        $data["option_type"]=$orderType;
        $data["apply_uid"]=UID;
        $pay_name=$this->getMemberModel()->newQuery()->where("uid",UID)->value("nickname");
        $data["apply_name"]=$pay_name;
        $data["wx_no"]=$orderInfo->wx_no;
        $data["wx_name"]=$orderInfo->wx_name;
        $data["sale_id"]=$orderInfo->sale_id;
        $data["sale_name"]=$orderInfo->sale_name;
        $data["add_fen_type"]=$orderInfo->add_fen_type;
        $data["add_fen_month"]=$orderInfo->add_fen_month;
        $data["pt_name"]=$orderInfo->pt_name;
        $data["pay_type"]=$orderInfo->pay_type;
        $data["create_time"]=time();
        $data["update_time"]=time();
        return $this->newQuery()->insert($data);
    }



}
